package com.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.crm.common.ResVo;
import com.crm.entity.Photos;
import com.crm.service.PhotosService;
import com.spring4all.swagger.EnableSwagger2Doc;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@EnableSwagger2Doc
@RequestMapping("/photos")
@Api(tags = "图片管理")
public class PhotosController {

	@Autowired
	private PhotosService photosService;
	
	@GetMapping("/findPhotos/{category}")
	@ApiOperation("按类别查询图片")
	public ResVo<Object> findPhotosByCategory(@PathVariable @ApiParam("图片类别") String category) {
		List<Photos> message = photosService.findPhotosByCategory(category);
		return ResVo.success(message);
	}
	
	@GetMapping("/getPhotosByPage/{pageIndex}")
	@ApiOperation("获取图片列表带分页")
	public ResVo<Object> getPhotosByPage(@RequestParam(value="title",required=false) @ApiParam("图片标题")  String title,
			@PathVariable("pageIndex") @ApiParam("页码") Integer pageIndex) {
		Page<Photos> message = photosService.getPhotosByPage(pageIndex, title);
		return ResVo.success(message);
	}
	
	@PostMapping("/addPhotos")
	@ApiOperation("添加图片")
	public ResVo<Object> addPhotos(@RequestBody Photos photos) {
		photosService.addPhotos(photos);
		return ResVo.defaultSuccess();
	}
	
	
	@GetMapping("/getPhotos/{id}")
	@ApiOperation("根据图片id查询图片信息")
	public ResVo<Object> getPhotosById(@PathVariable @ApiParam("图片id") String id) {
		Photos photos = photosService.getPhotosById(id);
		return ResVo.success(photos);
	}
	
}
